package com.carbon.trade.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.carbon.common.exception.CommonBizException;
import com.carbon.domain.common.constant.RocketDelayLevelConstant;
import com.carbon.domain.common.constant.RocketMqName;
import com.carbon.domain.trade.vo.MqCarbonTradeQuote;
import com.carbon.trade.common.enums.TradeRoleEnum;
import com.carbon.trade.common.enums.TradeStatusEnum;
import com.carbon.trade.entity.CarbonTradePrice;
import com.carbon.trade.entity.CarbonTradeQuote;
import com.carbon.trade.mapper.CarbonTradeQuoteMapper;
import com.carbon.trade.param.StartTradingParam;
import com.carbon.trade.repository.EsCarbonTradeQuoteRepository;
import com.carbon.trade.service.CarbonTradePriceService;
import com.carbon.trade.service.CarbonTradeQuoteService;
import com.carbon.trade.param.CarbonTradeQuoteQueryParam;
import com.carbon.trade.vo.CarbonTradeQuoteQueryVo;
import com.carbon.common.service.BaseServiceImpl;
import com.carbon.common.api.Paging;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.elasticsearch.common.lucene.search.function.FunctionScoreQuery;
import org.elasticsearch.index.query.BoolQueryBuilder;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.index.query.functionscore.FunctionScoreQueryBuilder;
import org.elasticsearch.index.query.functionscore.ScoreFunctionBuilders;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.elasticsearch.core.ElasticsearchRestTemplate;
import org.springframework.data.elasticsearch.core.SearchHit;
import org.springframework.data.elasticsearch.core.SearchHits;
import org.springframework.data.elasticsearch.core.query.NativeSearchQuery;
import org.springframework.data.elasticsearch.core.query.NativeSearchQueryBuilder;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import javax.annotation.Resource;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.util.StringUtils;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;


/**
 * <p>
 * 碳交易供需行情 服务实现类
 * </p>
 *
 * @author lin rizhao
 * @since 2022-05-21
 */
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
public class CarbonTradeQuoteServiceImpl extends BaseServiceImpl<CarbonTradeQuoteMapper, CarbonTradeQuote> implements CarbonTradeQuoteService {
    @Autowired
    private CarbonTradeQuoteMapper carbonTradeQuoteMapper;

    @Override
    public ArrayList getDeliveryMethod(String type) {
        return carbonTradeQuoteMapper.getDeliveryMethod(type);
    }

    @Override
    public String getDeliveryMethodByName(String deliveryMethod) {
        return null;
    }

    @Override
    public String getDeliveryExchangeByName(String deliveryMethod) {
        return null;
    }

    @Override
    public IPage<CarbonTradeQuote> handleSearch(Page<CarbonTradeQuote> page,CarbonTradeQuoteQueryParam param) {
        return carbonTradeQuoteMapper.handleSearch(page,param);
    }

    @Override
    public String transferType(String assetType) {
        return carbonTradeQuoteMapper.transferType(assetType);
    }

    @Override
    public String transferNumToChinese(String assetType) {
        return carbonTradeQuoteMapper.transferNumToChinese(assetType);
    }

}
